﻿using Marknic.TestRunner.Rigging;
using NetduinoHappyHour.Asynchronous;
using NetduinoHappyHour.Behaviour;
using NetduinoHappyHour.Hardware;
using NetduinoHappyHour.Util;
using NetduinoHappyHour;

namespace NetduinoTest
{
    
    /// <summary>
    ///This is a test class for ObjectFactoryTest and is intended
    ///to contain all ObjectFactoryTest Unit Tests
    ///</summary>
    public class ObjectFactoryTest
    {


        /// <summary>
        ///A test for CreateObjectByNameAndParam
        ///</summary>
        public void TestCreateObjectByNameAndParam()
        {
            ObjectFactory target = new ObjectFactory();
            // namespace behaviour
            string SimpleObjectDescription = "BackForth";
            // namespace behaviour
            string SimpleObjectDescriptionWithBraces = "BackForth(  )";
            // namespace Asynchronous
            string DoubleObjectDescription = "ExecuteAsync(BackForth)";
            // namespace Hardware
            string ObjectDescriptionWithParam = "DriveCommand(10,20,30)";
            //special testcase
            string UpdateCommand = "UpdateRunningCommand(IsPaused,true,bool)";
            object actual;
            actual = target.CreateObjectByNameAndParam(SimpleObjectDescription);
            Assert.IsTrue(actual is BackForth);
            actual = null;
            actual = target.CreateObjectByNameAndParam(SimpleObjectDescriptionWithBraces);
            Assert.IsTrue(actual is BackForth);
            actual = target.CreateObjectByNameAndParam(DoubleObjectDescription);
            Assert.IsTrue(actual is ExecuteAsync);
            actual = target.CreateObjectByNameAndParam(ObjectDescriptionWithParam);
            Assert.IsTrue(actual is DriveCommand);
            Assert.Equals(((DriveCommand)actual).StepsToRunL, 10);
            Assert.Equals(((DriveCommand)actual).StepsToRunR, 20);
            actual = target.CreateObjectByNameAndParam(UpdateCommand);
            Assert.IsNotNull(actual);
            // for further tests on update see UpdateObjectTest 
            DriveCommandDualAsync dCommand = new DriveCommandDualAsync(1000);
            ((UpdateRunningCommand)actual).ObjectToUpdate = dCommand;
            ((IExecutable)actual).Execute();
            Assert.IsTrue(dCommand.Left.IsPaused);
        }
    }
}
